package models;

import java.util.List;

import javax.persistence.Entity;

import play.db.jpa.Model;
import play.libs.Codec;

@Entity
public class User extends Model {
	public String screenName;
	public String passwordHash;
	public String apiKey;
	public String apiID;
	public String email;

	public User(String screenName, String passwordHash, String apiKey,
			String apiID, String email) {
		super();
		this.screenName = screenName;
		this.passwordHash = Codec.hexMD5(passwordHash);
		this.apiKey = apiKey;
		this.apiID = apiID;
		this.email = email;
	}

	public boolean verifyPassword(String password) {
		return Codec.hexMD5(password).equals(passwordHash);
	}

	// -- User find utility methods
	public static User findByEmail(String email) {
		return User.find("email=?", email).first();
	}

	public static User findByApiID(String id) {
		return User.find("apiID=?", id).first();
	}

	public static User findByApiKey(String key) {
		return User.find("apiKey", key).first();
	}
}
